package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import easier.app.x.service.CommandService;

public class MainActivity42 extends AppCompatActivity {

    private Button mCommand00;
    private Button mCommand01;
    private Button mCommand02;
    private Button mCommand03;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity42.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main42 );
        initView();
        initViewAction();
    }

    private void initView() {

        mCommand00 = (Button) findViewById( R.id.command00 );
        mCommand01 = (Button) findViewById( R.id.command01 );
        mCommand02 = (Button) findViewById( R.id.command02 );
        mCommand03 = (Button) findViewById( R.id.command03 );
    }

    private void initViewAction() {

        mCommand00.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View view ) {

                CommandService.sendCommand( view.getContext(), MainActivity42Service.class, 0, "Hello Service" );
            }
        } );

        mCommand01.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View view ) {

                CommandService
                    .sendCommand( view.getContext(), MainActivity42Service.class, 1, new Bean( 1, "Hello service again" ) );
            }
        } );

        mCommand02.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View view ) {

                CommandService.sendCommand( view.getContext(), MainActivity42ServiceRemote.class, 0, "Hello Service" );
            }
        } );

        mCommand03.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View view ) {

                CommandService
                    .sendCommand( view.getContext(), MainActivity42ServiceRemote.class, 1, new Bean( 1, "Hello service again" ) );
            }
        } );
    }

    public static class Bean {

        public int key;
        public String value;

        public Bean() {

        }

        public Bean( int key, String value ) {

            this.key = key;
            this.value = value;
        }
    }
}